<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:phi="http://java.sun.com/jsf/composite/pharmacy"
                xmlns:bi="http://java.sun.com/jsf/composite/bill"
                xmlns:pa="http://java.sun.com/jsf/composite/paymentMethod"
                xmlns:pat="http://java.sun.com/jsf/composite/patient">



    <ui:define name="content">


        <h:panelGroup rendered="#{!(webUserController.hasPrivilege('OpdCollectingCentreBilling') or webUserController.hasPrivilege('LabCashier'))}" >
            You are NOT authorized
        </h:panelGroup>

        <h:panelGroup rendered="#{webUserController.hasPrivilege('OpdCollectingCentreBilling') or webUserController.hasPrivilege('LabCashier')}" styleClass="opdPanel" >
            <h:form id="form">

                <p:panel  >
                    <f:facet name="header" rendered="#{!collectingCentreBillController.printPreview}">
                        <h:panelGrid columns="6" rendered="#{!collectingCentreBillController.printPreview}">
                            <h:outputLabel value="Collecting Centre Billing"/>
                            <p:spacer width="20" height="1" ></p:spacer>
                            <p:commandButton  value="Settle" action="#{collectingCentreBillController.settleBill}" ajax="false"  style="width: 200px; padding: 1px;border: 1px solid ; margin: auto;">
                            </p:commandButton>
                            <p:commandButton value="New Bill" ajax="false" action="#{collectingCentreBillController.prepareNewBill()}" >
                            </p:commandButton>
                            <p:commandButton value="Print Last Bill" ajax="false" action="opd_bill_print_last" >
                            </p:commandButton>
                            <p:focus id="focusIx" for="acIx" />
                        </h:panelGrid>
                    </f:facet>
                    <h:panelGroup rendered="#{!collectingCentreBillController.printPreview}" styleClass="alignTop" >
                        <p:panel style="min-height: 600px; position:relative;"  >




                            <h:panelGrid columns="2" >

                                <h:panelGrid columns="1" >

                                    <h:panelGroup id="panelPatient" >

                                        <p:tabView id="tvPt" activeIndex="#{collectingCentreBillController.patientSearchTab}"  >
                                            <p:ajax event="tabChange"   process="@this"  
                                                    update=":#{p:component('tblBillItem')} :#{p:component('pBillDetails')} "
                                                    listener="#{collectingCentreBillController.onTabChange}" />

                                            <p:tab id="tabNewPt" title="New Patient"   >


                                                <table >
                                                    <tr >
                                                        <td >
                                                            <p:outputLabel value="Title &amp; Name" ></p:outputLabel>
                                                        </td>
                                                        <td> : </td>
                                                        <td >
                                                            <p:selectOneMenu  id="cmbTitle"  
                                                                              value="#{collectingCentreBillController.newPatient.person.title}"  >
                                                                <f:selectItem itemLabel="Select Title" />
                                                                <f:selectItems value="#{collectingCentreBillController.title}" var="i" 
                                                                               itemLabel="#{i.label}" itemValue="#{i}"/>
                                                            </p:selectOneMenu>

                                                        </td>
                                                        <td  >
                                                            <p:inputText autocomplete="off"  id="txtNewPtName" placeholder="Name"
                                                                         value="#{collectingCentreBillController.newPatient.person.name}" 
                                                                         style="width: 350px;text-transform:capitalize;">
                                                            </p:inputText>
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td>
                                                            <p:outputLabel value="Sex &amp; Age" ></p:outputLabel>
                                                        </td>
                                                        <td> : </td>
                                                        <td>
                                                            <p:selectOneMenu id="txtNewSex"  value="#{collectingCentreBillController.newPatient.person.sex}" >
                                                                <f:selectItem itemLabel="Select Sex"/>
                                                                <f:selectItems value="#{collectingCentreBillController.sex}"/>
                                                            </p:selectOneMenu>
                                                        </td>
                                                        <td>
                                                            <h:panelGrid columns="4">
                                                                <p:inputText autocomplete="off"  id="year"  
                                                                             value="#{collectingCentreBillController.yearMonthDay.year}" 
                                                                             style="width: 50px; ">
                                                                    <f:ajax event="keyup" execute="@this month day" render="calNewPtDob" 

                                                                            listener="#{collectingCentreBillController.dateChangeListen()}"  />
                                                                </p:inputText>
                                                                <p:inputText autocomplete="off" id="month"
                                                                             style="width: 50px; " value="#{collectingCentreBillController.yearMonthDay.month}">
                                                                    <f:ajax event="keyup" execute="@this year day" render="calNewPtDob" listener="#{collectingCentreBillController.dateChangeListen()}"  />
                                                                </p:inputText>
                                                                <p:inputText autocomplete="off" id="day" 
                                                                             style="width: 50px;" value="#{collectingCentreBillController.yearMonthDay.day}">
                                                                    <f:ajax event="keyup" execute="@this year month" render="calNewPtDob" listener="#{collectingCentreBillController.dateChangeListen()}" />
                                                                </p:inputText>
                                                                <p:calendar  value="#{collectingCentreBillController.newPatient.person.dob}" 
                                                                             id="calNewPtDob"  navigator="true" pattern="dd/MM/yyyy" 
                                                                             style="width: 100px!important;"
                                                                             styleClass="shortinput">
                                                                    <f:ajax event="dateSelect" />
                                                                </p:calendar>
                                                            </h:panelGrid>
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td>
                                                            <h:outputLabel value="Phone,Area &amp; Nic"/>
                                                        </td>
                                                        <td> : </td>
                                                        <td>
                                                            <p:inputMask mask="999-9999999" id="txtNewPtPhone" placeholder="Phone Number"
                                                                         autocomplete="off" maxlength="11" 
                                                                         value="#{collectingCentreBillController.newPatient.person.phone}"
                                                                         style="width: 100px;">
                                                            </p:inputMask>
                                                        </td>
                                                        <td>
                                                            <p:autoComplete id="acNewPtArea" converter="areaCon" placeholder="Select Area"
                                                                            completeMethod="#{areaController.completeArea}" 
                                                                            var="pta" itemLabel="#{pta.name}" styleClass="shortinput"
                                                                            itemValue="#{pta}" forceSelection="true" 
                                                                            value="#{collectingCentreBillController.newPatient.person.area}" ></p:autoComplete>
                                                            <!--<p:inputMask placeholder="NIC" mask="999999999V" value="#{collectingCentreBillController.newPatient.person.nic}" />-->
                                                            <p:inputText placeholder="NIC" maxlength="12" value="#{collectingCentreBillController.newPatient.person.nic}"/>


                                                        </td>

                                                    </tr>
                                                </table>

                                                <p:watermark value="YEAR" for="year" />
                                                <p:watermark value="MONTH" for="month" />
                                                <p:watermark value="DAYS" for="day" />
                                                <p:watermark for="calNewPtDob" value="Birthday" ></p:watermark>

                                            </p:tab>

                                            <p:tab id="tabSearchPt" title="Search Patient">

                                                <h:panelGrid columns="1" >

                                                    <p:autoComplete styleClass="mediuminput" converter="patientConverter"
                                                                    disabled="#{collectingCentreBillController.fromOpdEncounter}"
                                                                    widgetVar="aPt" id="acPt" forceSelection="true" 
                                                                    value="#{collectingCentreBillController.searchedPatient}" 
                                                                    completeMethod="#{patientController.completePatientByNameOrCode}" 
                                                                    var="apt" itemLabel="#{apt.person.name}" 
                                                                    itemValue="#{apt}" size="30"  style="width: 400px;"
                                                                    minQueryLength="4">


                                                        <p:column headerText="Name">
                                                            <h:outputLabel value="#{apt.person.nameWithTitle}" />
                                                        </p:column>

                                                        <p:column headerText="Age">
                                                            <h:outputLabel value="#{apt.age}" />
                                                        </p:column>
                                                        <p:column headerText="Code">
                                                            <h:outputLabel value="#{apt.code}" />
                                                        </p:column>
                                                        <p:column headerText="Sex">
                                                            <h:outputLabel value="#{apt.person.sex}" />
                                                        </p:column>
                                                        <p:column headerText="Address">
                                                            <h:outputLabel value="#{apt.person.address}" />
                                                        </p:column>
                                                        <p:column headerText="Date of Birth">
                                                            <h:outputLabel value="#{apt.person.dob}" >
                                                                <f:convertDateTime pattern="dd MMMM yyyy"/>
                                                            </h:outputLabel>
                                                        </p:column>
                                                        <f:ajax event="itemSelect" execute="@this" 
                                                                render="panSearch :#{p:component('tblBillItem')} :#{p:component('pBillDetails')}" 
                                                                listener="#{collectingCentreBillController.calTotals()}" />
                                                    </p:autoComplete>   

                                                    <h:panelGroup id="panSearch">
                                                        <pat:searchPatientDetail patient="#{collectingCentreBillController.searchedPatient}"  />
                                                    </h:panelGroup>

                                                    <div style="padding: 2px; margin: 2px; border: 1px solid;">
                                                        <p:outputLabel value="#{pharmacySaleController.opdEncounterComments}" ></p:outputLabel>
                                                    </div>

                                                </h:panelGrid>


                                            </p:tab>

                                        </p:tabView>

                                    </h:panelGroup>

                                    <h:panelGroup id="panelIx" >


                                        <p:panel id='pIxAdd' header="Items / Services" style="min-height: 350px;"  >
                                            <p:focus  context="acIx"/>

                                            <h:panelGrid columns="2" >
                                                <p:autoComplete widgetVar="aIx" id="acIx" forceSelection="true"
                                                                value="#{collectingCentreBillController.currentBillItem.item}" 
                                                                completeMethod="#{itemController.completeOpdItemsByNamesAndCode}"
                                                                var="ix" itemLabel="#{ix.name}" itemValue="#{ix}"
                                                                size="30"  style="width: 400px;"
                                                                placeholder="Select Investigation">
                                                    <p:column style="max-width: 200px;" headerText="Name">
                                                        <p:outputLabel value="#{ix.name}" ></p:outputLabel>
                                                        <h:panelGroup rendered="#{ix.name ne ix.fullName}" >
                                                            <p:outputLabel value=" (#{ix.fullName})" ></p:outputLabel>
                                                        </h:panelGroup>
                                                    </p:column>
                                                    <p:column style="max-width: 200px;" headerText="Dept">
                                                        <h:outputLabel value="#{ix.department.name}"></h:outputLabel>
                                                    </p:column>
                                                    <p:column style="text-align: right; max-width: 80px;" headerText="Value">
                                                        <h:outputLabel value="#{ix.total}"></h:outputLabel>
                                                    </p:column>
                                                    <p:ajax event="itemSelect"  listener="#{collectingCentreBillController.fillBillSessions}" process="acIx" update="tblSs" ></p:ajax>
                                                </p:autoComplete>
                                                <h:commandButton id="btnAddIx" value="Add" action="#{collectingCentreBillController.addToBill()}"  style="width: 75px;"  >
                                                    <f:ajax execute="acIx btnAddIx panelBillItems :#{p:component('acColl')}" render="focusIx tblBillItem  :#{p:component('pBillDetails')}  pIxAdd" />
                                                </h:commandButton>
                                                <p:defaultCommand target="btnAddIx" />
                                            </h:panelGrid>

                                            <p:panel header="Appointments"  >

                                                <p:panelGrid columns="2" >
                                                    <p:calendar id="calS" mode="inline" value="#{collectingCentreBillController.sessionDate}" pattern="dd MMMM yyyy" >
                                                        <f:ajax event="dateSelect" execute="calS" render="tblSs :#{p:component('lblTemS')}" />
                                                    </p:calendar>

                                                    <p:dataTable id="tblSs" value="#{collectingCentreBillController.billSessions}" var="bs" emptyMessage="No Numbers Yet">
                                                        <f:facet name="header">
                                                            <h:outputLabel value="#{collectingCentreBillController.lastBillItem.item.name}" />

                                                            <h:outputLabel id="lblTemS" value="#{collectingCentreBillController.sessionDate}" >
                                                                <f:convertDateTime pattern="dd MMM yyyy" ></f:convertDateTime>
                                                            </h:outputLabel>



                                                        </f:facet>
                                                        <p:column headerText="No.">
                                                            <h:outputLabel value="#{bs.serialNo}" />
                                                        </p:column>
                                                        <p:column headerText="Client">
                                                            <h:outputLabel value="#{bs.billItem.bill.patient.person.nameWithTitle}" />
                                                        </p:column>
                                                    </p:dataTable>

                                                </p:panelGrid>

                                            </p:panel>
                                        </p:panel>



                                    </h:panelGroup>

                                </h:panelGrid>


                                <h:panelGrid columns="1" >
                                    <p:panel >
                                        <h:panelGrid columns="2">


                                            <p:outputLabel value="Collecting Centre"></p:outputLabel>


                                            <p:autoComplete converter="deal" value="#{collectingCentreBillController.collectingCentre}" 
                                                            forceSelection="true" id="acColl"
                                                            completeMethod="#{institutionController.completeCollectingCenter}" 
                                                            var="vt" itemLabel="#{vt.name}" itemValue="#{vt}" >

                                                <f:ajax event="itemSelect" execute="@this" render="tblAgentBooks tblAgentBooks2 ballance2 ballance4 ballance6" listener="#{collectingCentreBillController.listnerSelectLabBooks()}" />
                                                <p:column>#{vt.institutionCode}</p:column>
                                                <p:column>#{vt.name}</p:column>
                                            </p:autoComplete>
                                            <p:dataTable emptyMessage="No Book"  id="tblAgentBooks" value="#{collectingCentreBillController.collectingCentre.agentReferenceBooks}" var="a" styleClass="noBorder summeryBorder">
                                                <p:column>
                                                    <f:facet name="header">
                                                        <p:outputLabel value="S.R.N." />
                                                    </f:facet>
                                                    <p:outputLabel value="#{a.startingReferenceNumber}" >
                                                        <f:convertNumber pattern="00000" />
                                                    </p:outputLabel>
                                                </p:column>.
                                            </p:dataTable>
                                            <p:dataTable  id="tblAgentBooks2" value="#{collectingCentreBillController.collectingCentre.agentReferenceBooks}" var="a" styleClass="noBorder summeryBorder">
                                                <p:column>
                                                    <f:facet name="header">
                                                        <p:outputLabel value="E.R.N." />
                                                    </f:facet>
                                                    <p:outputLabel value="#{a.endingReferenceNumber}" >
                                                        <f:convertNumber pattern="00000" />
                                                    </p:outputLabel>
                                                </p:column>
                                            </p:dataTable>



                                            <p:outputLabel value="Referance No"></p:outputLabel>
                                            <p:inputText value="#{collectingCentreBillController.referralId}" style="width: 80px"></p:inputText>
                                            <p:outputLabel value="Comments"></p:outputLabel>
                                            <p:inputTextarea value="#{collectingCentreBillController.comment}" id="comment"/>
                                            <p:outputLabel value="Referring Doctor"></p:outputLabel>
                                            <h:panelGrid columns="1">
                                                <p:autoComplete  forceSelection="true" id="cmbDoc" value="#{collectingCentreBillController.referredBy}" completeMethod="#{doctorController.completeDoctor}" var="ix" itemLabel="#{ix.person.name}" itemValue="#{ix}" size="30"  style="width: 200px;float: left;">
                                                </p:autoComplete>
                                                <p:commandButton id="btnAddNewDoc" type="button" value="Add Refering Doctor" onclick="dlg.show();" actionListener="#{doctorController.prepareAdd}" process="btnAddNewDoc" update="#{p:component('panDoc')}" />  
                                            </h:panelGrid>
                                            <p:outputLabel value="Refferal Institution"></p:outputLabel>
                                            <p:autoComplete forceSelection="true" id="cmdIns" 
                                                            value="#{collectingCentreBillController.referredByInstitution}" 
                                                            completeMethod="#{institutionController.completeIns}" var="refi" 
                                                            itemLabel="#{refi.name}" itemValue="#{refi}" converter="institutionConverter">
                                                <p:column headerText="Name">
                                                    #{refi.name}
                                                </p:column>
                                                <p:column headerText="Code">
                                                    #{refi.institutionCode}
                                                </p:column>
                                                <p:column headerText="Institution Type">
                                                    #{refi.institutionType}
                                                </p:column>
                                            </p:autoComplete>
                                            <h:outputLabel id="ballance" value="Ballance"   />
                                            <h:outputLabel id="ballance2" value="#{collectingCentreBillController.collectingCentre.ballance}">
                                                <f:convertNumber  pattern="#,##0.00"/>
                                            </h:outputLabel>
                                            <h:outputLabel id="ballance3" value="Max Credit Limit"/>                                          
                                            <h:outputLabel id="ballance4" value="#{collectingCentreBillController.collectingCentre.maxCreditLimit}">
                                                <f:convertNumber  pattern="#,##0.00"/>
                                            </h:outputLabel>
                                            <h:outputLabel id="ballance5" value="Credit Limit"   />
                                            <h:outputLabel id="ballance6" value="#{collectingCentreBillController.collectingCentre.allowedCredit}">
                                                <f:convertNumber  pattern="#,##0.00"/>
                                            </h:outputLabel>
                                        </h:panelGrid>

                                    </p:panel>




                                    <p:dialog id="panDoc" header="Add New Doctor" widgetVar="dlg" resizable="false">  
                                        <h:panelGrid columns="2" style="margin-bottom:10px">  
                                            <h:outputText id="lblNameD" value="Name" ></h:outputText>
                                            <h:inputText autocomplete="off" id="txtNameD"  value="#{doctorController.current.person.name}"  ></h:inputText>
                                            <h:outputText id="lblPhoneD" value="Phone" ></h:outputText>
                                            <h:inputText autocomplete="off" id="txtPhoneD" value="#{doctorController.current.person.phone}"  ></h:inputText>
                                            <h:outputText id="lblFaxD" value="Fax" ></h:outputText>
                                            <h:inputText autocomplete="off" id="txtFaxD" value="#{doctorController.current.person.fax}"  ></h:inputText>
                                            <h:outputText id="lblMobileD" value="Mobile" ></h:outputText>
                                            <h:inputText autocomplete="off" id="txtMobileD" value="#{doctorController.current.person.mobile}"  ></h:inputText>
                                            <h:outputText id="lblAddressD" value="Address" ></h:outputText>
                                            <h:inputText autocomplete="off" id="txtAddressD" value="#{doctorController.current.person.address}"  ></h:inputText>
                                            <h:outputText value="Speciality" ></h:outputText>                                    
                                            <h:selectOneListbox id="cmbSpecialityD" size="1" value="#{doctorController.current.speciality}" >
                                                <f:selectItem itemLabel="Please select a speciality"/>
                                                <f:selectItems value="#{specialityController.items}" var="cat" itemLabel="#{cat.name}" itemValue="#{cat}" />
                                            </h:selectOneListbox>
                                            <h:outputText id="lblRegD" value="Registration" ></h:outputText>
                                            <h:inputText autocomplete="off" id="txtRegD" value="#{doctorController.current.registration}"  ></h:inputText>                 
                                            <h:outputText id="lblQuaD" value="Qualification" ></h:outputText>
                                            <h:inputText autocomplete="off" id="txtQuaD" value="#{doctorController.current.qualification}"  ></h:inputText>   

                                            <p:commandButton id="btnDocSave" value="Add New" process="btnDocSave panDoc" update="panDoc :#{p:component('cmbDoc')}" actionListener="#{doctorController.saveSelected()}" styleClass="buttons" oncomplete="dlg.hide();">
                                            </p:commandButton>

                                        </h:panelGrid>  

                                    </p:dialog>  



                                    <h:panelGroup id="panelBillItems" >


                                        <p:tabView id="tblBillItem" >





                                            <p:tab id="tabBillItems" title="Bill Items" >
                                                <p:dataTable id="tblRequests" rowIndexVar="rowIndex" value="#{collectingCentreBillController.lstBillEntries}" var="bi" >

                                                    <p:column>
                                                        <f:facet name="header">No</f:facet>
                                                            #{rowIndex+1}
                                                    </p:column>
                                                    <p:column>
                                                        <f:facet name="header">Item</f:facet>
                                                            #{bi.billItem.item.name}
                                                    </p:column>
                                                    <p:column>
                                                        <f:facet name="header">Fee</f:facet>
                                                        <h:outputLabel value="#{bi.billItem.netValue}">
                                                            <f:convertNumber pattern="#,##0.00" />
                                                        </h:outputLabel>
                                                    </p:column>
                                                    <p:column>
                                                        <f:facet name="header">Department</f:facet>
                                                            #{bi.billItem.item.department.name}
                                                    </p:column>

                                                    <p:column>
                                                        <h:commandButton id="btnRemove" value="X" action="#{collectingCentreBillController.removeBillItem}" >
                                                            <f:setPropertyActionListener  value="#{rowIndex}" target="#{collectingCentreBillController.index}" />
                                                            <p:ajax  process="btnRemove" update=":#{p:component('tblBillItem')} :#{p:component('pBillDetails')}" />
                                                        </h:commandButton>
                                                    </p:column>
                                                </p:dataTable>
                                            </p:tab>
                                            <p:tab id="tabBillIx" title="Tests" >
                                                <p:dataTable rowIndexVar="rowIndex" value="#{collectingCentreBillController.lstBillComponents}" var="bix" >
                                                    <p:column>
                                                        <f:facet name="header">No</f:facet>
                                                            #{rowIndex+1}
                                                    </p:column>
                                                    <p:column>
                                                        <f:facet name="header">Name</f:facet>
                                                            #{bix.item.name}
                                                    </p:column>

                                                </p:dataTable>
                                            </p:tab>

                                            <p:tab id="tabBillFee" title="Fees" >
                                                <p:dataTable rowIndexVar="rowIndex" value="#{collectingCentreBillController.lstBillFees}" var="bif" >
                                                    <p:column>
                                                        <f:facet name="header">Item Name</f:facet>
                                                        <h:outputLabel value="#{bif.billItem.item.name}" />
                                                    </p:column>
                                                    <p:column>
                                                        <f:facet name="header">Fee</f:facet>
                                                        <h:inputText autocomplete="off"  
                                                                     id="txtFeeVal"
                                                                     value="#{bif.feeGrossValue}" disabled="#{!bif.billItem.item.userChangable}" >
                                                            <f:convertNumber pattern="#,##0.00" />
                                                            <f:ajax event="keyup" execute="@this" 
                                                                    render=":#{p:component('tblRequests')}  :#{p:component('pBillDetails')}"
                                                                    listener="#{collectingCentreBillController.feeChangeListener(bif)}" />
                                                        </h:inputText>
                                                    </p:column>
                                                    <p:column>
                                                        <p:commandButton ajax="false" value="Update" action="#{collectingCentreBillController.feeChangeListener(bif)}" />
                                                    </p:column>
                                                    <p:column>
                                                        <f:facet name="header">Fee Name</f:facet>
                                                        <h:outputLabel value="#{bif.fee.name}" rendered="#{bif.fee !=null}" ></h:outputLabel>
                                                    </p:column>



                                                    <p:column>
                                                        <f:facet name="header">Speciality</f:facet>
                                                        <h:outputLabel value="#{bif.fee.speciality.name}" rendered="#{bif.fee !=null and bif.fee.speciality!=null}" ></h:outputLabel>
                                                    </p:column>

                                                    <p:column>
                                                        <f:facet name="header">Payee</f:facet>                                                
                                                        <p:selectOneMenu value="#{bif.staff}" rendered="#{bif.fee.speciality!=null}" >
                                                            <f:selectItem itemLabel="Select Staff" />
                                                            <f:selectItems  value="#{staffController.getSpecialityStaff(bif.fee.speciality)}" var="bifs" itemLabel="#{bifs.person.name}" itemValue="#{bifs}" />
                                                        </p:selectOneMenu>

                                                    </p:column>
                                                </p:dataTable>
                                            </p:tab>
                                        </p:tabView>
                                    </h:panelGroup>


                                    <h:panelGroup>
                                        <h:panelGroup id="panelBillTotals" >
                                            <p:panel header="Bill Details" id="pBillDetails"  >
                                                <p:panelGrid columns="2" columnClasses="numberCol, textCol"  >
                                                    <h:outputLabel value="Total" ></h:outputLabel >
                                                    <h:outputLabel id="tot" value="#{collectingCentreBillController.total}" >
                                                        <f:convertNumber pattern="#,##0.00" />
                                                    </h:outputLabel>
                                                    <h:outputLabel value="Discount" ></h:outputLabel>
                                                    <h:outputLabel id="dis" value="#{collectingCentreBillController.discount}" >
                                                        <f:convertNumber pattern="#,##0.00" />
                                                    </h:outputLabel>
                                                    <h:outputLabel value="Net Total" ></h:outputLabel>
                                                    <h:outputLabel id="netTotal" value="#{collectingCentreBillController.netTotal}" >
                                                        <f:convertNumber pattern="#,##0.00" />
                                                    </h:outputLabel>
                                                    <h:outputLabel value="VAT" ></h:outputLabel>
                                                    <h:outputLabel id="vat" value="#{collectingCentreBillController.vat}" >
                                                        <f:convertNumber pattern="#,##0.00" />
                                                    </h:outputLabel>
                                                    <h:outputLabel value="VAT &amp; Net Total" ></h:outputLabel>
                                                    <h:outputLabel id="vatPlusNetTotal" value="#{collectingCentreBillController.vatPlusNetTotal}" >
                                                        <f:convertNumber pattern="#,##0.00" />
                                                    </h:outputLabel>
                                                </p:panelGrid>

                                            </p:panel>
                                        </h:panelGroup>

                                    </h:panelGroup>


                                </h:panelGrid>


                            </h:panelGrid>
                        </p:panel>
                    </h:panelGroup>

                    <h:panelGroup rendered="#{collectingCentreBillController.printPreview}" >
                        <h:panelGroup rendered="#{sessionController.loggedPreference.opdBillPaperType eq 'FiveFivePaper'}">

                            <h:panelGroup rendered="#{sessionController.loggedPreference.printLabelForOPdBill eq false 
                                                      and sessionController.loggedPreference.applicationInstitution eq 'Ruhuna'
                                                      and sessionController.loggedPreference.fiveFivePaperWithHeadings eq false}">
                                <div class="nonPrintBlock">
                                    <p:commandButton value="Print" 
                                                     process="@this" 
                                                     update="@all" 
                                                     type="button"  
                                                     ajax="false">
                                        <p:printer target="gpBillPreview" ></p:printer>
                                    </p:commandButton>
                                    <p:commandButton value="Print Patient" 
                                                     process="@this" 
                                                     update="@all" 
                                                     type="button"  
                                                     ajax="false">
                                        <p:printer target="gpBillPreview2" ></p:printer>
                                    </p:commandButton>

                                    <p:commandButton value="New Bill" ajax="false" action="#{collectingCentreBillController.prepareNewBill()}" >
                                    </p:commandButton>
                                    <p:commandButton ajax="false" value="Batch Cancel" action="#{collectingCentreBillController.cancellAll}" style="float: right;"
                                                     onclick="if (!confirm('Are you sure you want to Cancel This Bill ?'))
                                                                 return false;"/>
                                </div>
                                <h:panelGroup id="gpBillPreview">
                                    <ui:repeat value="#{collectingCentreBillController.bills}" var="bill">
                                        <bi:opdCCBillPrintRuhunu bill="#{bill}" dup="false"/>
                                    </ui:repeat>
                                </h:panelGroup>
                                <h:panelGroup id="gpBillPreview2">
                                    <ui:repeat value="#{collectingCentreBillController.bills}" var="bill">
                                        <bi:opdCCBillPrintRuhunu_1 bill="#{bill}" dup="false"/>
                                    </ui:repeat>
                                </h:panelGroup>
                            </h:panelGroup>

                            <h:panelGroup rendered="#{sessionController.loggedPreference.printLabelForOPdBill eq true}">

                                <div class="nonPrintBlock">
                                    <p:commandButton value="Print" ajax="false" action="#"  >
                                        <p:printer target="gpBillPreviewCoop" ></p:printer>
                                    </p:commandButton>

                                    <p:commandButton value="New Bill" ajax="false" action="#{collectingCentreBillController.prepareNewBill()}" >
                                    </p:commandButton>

                                    <p:commandButton ajax="false" value="Batch Cancel" action="#{collectingCentreBillController.cancellAll}" style="float: right;"
                                                     onclick="if (!confirm('Are you sure you want to Cancel This Bill ?'))
                                                                 return false;"/>
                                </div>
                                <h:panelGroup id="gpBillPreviewCoop">
                                    <ui:repeat value="#{collectingCentreBillController.bills}" var="b">
                                        <bi:opdBillPrintCoop bill="#{b}" dup="false"/>                        
                                    </ui:repeat>
                                </h:panelGroup>
                            </h:panelGroup>

                            <h:panelGroup rendered="#{sessionController.loggedPreference.fiveFivePaperWithHeadings eq true}">

                                <div class="nonPrintBlock">
                                    <p:commandButton value="Print" ajax="false" action="#"  >
                                        <p:printer target="fiveFivePaperWithHeadings" ></p:printer>
                                    </p:commandButton>

                                    <p:commandButton value="New Bill" ajax="false" action="#{collectingCentreBillController.prepareNewBill()}" >
                                    </p:commandButton>

                                    <p:commandButton ajax="false" value="Batch Cancel" action="#{collectingCentreBillController.cancellAll}" style="float: right;"
                                                     onclick="if (!confirm('Are you sure you want to Cancel This Bill ?'))
                                                                 return false;"/>
                                </div>
                                <h:panelGroup id="fiveFivePaperWithHeadings">
                                    <ui:repeat value="#{collectingCentreBillController.bills}" var="b">
                                        <bi:five_five_paper_with_headings bill="#{b}"/>                        
                                    </ui:repeat>
                                </h:panelGroup>
                            </h:panelGroup>

                            <h:panelGroup rendered="#{sessionController.loggedPreference.applicationInstitution eq 'Rmh'}">

                                <div class="nonPrintBlock">
                                    <p:commandButton value="Print" ajax="false" action="#"  >
                                        <p:printer target="gpBillPreviewRmh" ></p:printer>
                                    </p:commandButton>

                                    <p:commandButton value="New Bill" ajax="false" action="#{collectingCentreBillController.prepareNewBill()}" >
                                    </p:commandButton>

                                    <p:commandButton ajax="false" value="Batch Cancel" action="#{collectingCentreBillController.cancellAll}" style="float: right;"
                                                     onclick="if (!confirm('Are you sure you want to Cancel This Bill ?'))
                                                                 return false;"/>
                                </div>
                                <h:panelGroup id="gpBillPreviewRmh">
                                    <ui:repeat value="#{collectingCentreBillController.bills}" var="b">
                                        <bi:opdBillPrintRmh bill="#{b}" dup="false"/>                        
                                    </ui:repeat>
                                </h:panelGroup>
                            </h:panelGroup>

                        </h:panelGroup>

                        <h:panelGroup rendered="#{sessionController.loggedPreference.opdBillPaperType eq 'PosPaper'}">
                            <h:panelGrid rendered="#{sessionController.loggedPreference.opdPosBillWithoutLogo eq false}">
                                <div class="nonPrintBlock">
                                    <p:commandButton value="Print" ajax="false" action="#"  >
                                        <p:printer target="gpPosBill" ></p:printer>
                                    </p:commandButton>

                                    <p:commandButton value="New Bill" ajax="false" action="#{collectingCentreBillController.prepareNewBill()}" >
                                    </p:commandButton>

                                    <p:commandButton ajax="false" value="Batch Cancel" action="#{collectingCentreBillController.cancellAll}" style="float: right;"
                                                     onclick="if (!confirm('Are you sure you want to Cancel This Bill ?'))
                                                                 return false;"/>
                                </div>
                                <h:panelGroup id="gpPosBill">
                                    <div style="page-break-after: always;">
                                        <ui:repeat value="#{collectingCentreBillController.bills}" var="b">
                                            <bi:posOpdBill bill="#{b}" duplicate="false"/>                        
                                        </ui:repeat>
                                    </div>
                                    <div></div>
                                    <div style="page-break-after: always;">
                                        <ui:repeat value="#{collectingCentreBillController.bills}" var="b">
                                            <bi:posOpdBill bill="#{b}" duplicate="false"/>                        
                                        </ui:repeat>
                                    </div>
                                </h:panelGroup>
                            </h:panelGrid>




                            <h:panelGrid rendered="#{sessionController.loggedPreference.opdPosBillWithoutLogo eq true}">
                                <div class="nonPrintBlock">
                                    <p:commandButton value="Print" ajax="false" action="#"  >
                                        <p:printer target="gpPosBillWithoutLogo" ></p:printer>
                                    </p:commandButton>

                                    <p:commandButton value="New Bill" ajax="false" action="#{collectingCentreBillController.prepareNewBill()}" >
                                    </p:commandButton>

                                    <p:commandButton ajax="false" value="Batch Cancel" action="#{collectingCentreBillController.cancellAll}" style="float: right;"
                                                     onclick="if (!confirm('Are you sure you want to Cancel This Bill ?'))
                                                                 return false;"/>
                                </div>
                                <h:panelGroup id="gpPosBillWithoutLogo">
                                    <div style="page-break-after: always;">
                                        <ui:repeat value="#{collectingCentreBillController.bills}" var="b">
                                            <bi:posOpdBillWithoutLogo bill="#{b}" duplicate="false"/>                        
                                        </ui:repeat>
                                    </div>                                
                                </h:panelGroup>
                            </h:panelGrid>

                        </h:panelGroup>

                    </h:panelGroup>
                </p:panel>
            </h:form>

        </h:panelGroup>




    </ui:define>
</ui:composition>
